package com.rwx.myjava02springboot.controller;

import com.rwx.myjava02springboot.vo.User;
import org.springframework.format.annotation.DateTimeFormat;
import org.springframework.web.bind.annotation.*;

import java.time.LocalDateTime;
import java.util.List;

@RestController
public class RequestController {


    @RequestMapping("/simpleParam")
    public String simpleParam(String name,Integer age) {
        System.out.println(name+"  :  "+age);
        return "ok";
    }
    @RequestMapping(value = "/simpleParam02",method = RequestMethod.POST)
    public String simpleParam02(String name,Integer age) {
        System.out.println(name+"  :  "+age);
        return "ok";
    }
    @RequestMapping("/simpleParam03")
    public String simpleParam03(@RequestParam("name") String username , Integer age ){//请求参数名和形参名不相同
        System.out.println(username+"  :  "+age);
        return "OK";
    }

    @RequestMapping("/simplePojo")
    public String simplePojo(User user){//请求参数名和形参名不相同
        System.out.println(user);
        System.out.println(user.getName()+"  :  "+user.getAge());
        return "OK";
    }
    @RequestMapping("/complexPojo")
    public String complexPojo(User user){//请求参数名和形参名不相同
        System.out.println(user);
        System.out.println(user.getName()+"  :  "+user.getAge());
        return "OK";
    }

    @RequestMapping("/arrayParam")
    public String arrayParam(String[] hobby){//请求参数名和形参名不相同
        System.out.println(hobby.toString());
        return "OK";
    }

    @RequestMapping("/listParam")
    public String listParam(@RequestParam List<String> hobby){//请求参数名和形参名不相同
        System.out.println(hobby.toString());
        return "OK";
    }

    @RequestMapping("/dateParam")
    public String dateParam(@DateTimeFormat(pattern = "yyyy-MM-dd HH:mm:ss")LocalDateTime updateTime){//请求参数名和形参名不相同
        System.out.println(updateTime);
        return "OK";
    }

    @RequestMapping("/jsonParam")
    public String jsonParam(@RequestBody User user){
        System.out.println(user);
        return "OK";
    }
}
